<?php

namespace common\models\sys;

use Yii;

/**
 * This is the model class for table "admin_card_attachment".
 *
 * @property integer $id
 * @property string $filename
 * @property string $fileurl
 * @property integer $type
 * @property string $remark
 * @property integer $isvalid
 * @property string $create_time
 * @property string $update_time
 */
class Attachment extends \common\models\BaseModels
{
    const CARD_ATTACH_TYPE_BRAND = 0 ;
    
    public static $card_attach_list = [
        self::CARD_ATTACH_TYPE_BRAND => "卡卡项目商户品牌",
        
    ];

    const CARD_ATTACH_IS_VALID   = 1;
    const CARD_ATTACH_NOT_VALID  = 0;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'sys_attachment';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['filename'], 'required'],
            [['type', 'isvalid'], 'integer'],
            [['object_id','created_at', 'updated_at'], 'safe'],
            [['filename'], 'string', 'max' => 64],
            [['fileurl'], 'string', 'max' => 128],
            [['remark'], 'string', 'max' => 256],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app_table', 'ID'),
            'object_id'   => Yii::t('app_table', 'card attachment object ID'),
            'filename'    => Yii::t('app_table', 'card attachment filename'),
            'fileurl'     => Yii::t('app_table', 'card attachment fileurl'),
            'type'        => Yii::t('app_table', 'card attachment type'),
            'remark'      => Yii::t('app_table', 'card attachment remark'),
            'isvalid'     => Yii::t('app_table', 'isvalid'),
            'created_at' => Yii::t('app_table', 'create time'),
            'updated_at' => Yii::t('app_table', 'update time'),
        ];
    }

    /**
     * 添加附件记录
     */
    public function insertAttachment($param=[]){
        $attach = new CardAttachment;
        if (isset($param["filename"])) {
            $attach->filename =  $param["filename"];
        }
        if (isset($param["object_id"])) {
            $attach->object_id =  $param["object_id"];
        }
        if (isset($param["fileurl"])) {
            $attach->fileurl =  $param["fileurl"];
        }
        if (isset($param["type"])) {
            $attach->type =  $param["type"];
        }
        if (isset($param["remark"])) {
            $attach->remark =  $param["remark"];
        }
        
        $attach->isvalid = 1;
        if ($attach->save()) {
            return true;
        }

        return false;
    }

}
